// shopPages/storeList/storeList.js
import {oss_sign} from "../../utils/api.js";

const util = require('../../utils/util.js')
const app = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    titleName: '',
    page:1,
    more_status: true,
    show_start_free:0
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this
    that.data.titleName = options.name;
    that.setData({
      cat_id:options.cat_id
    });
    if (options.show_start_free!=undefined){
      that.setData({
        show_start_free: options.show_start_free
      });
    }
    // console.log(options)
    // wx.setNavigationBarTitle({
    //   title: options.name
    // }); 
    // 获取名片列表
    that.getSeller(options.cat_id);
  
  },
  getSeller: function (cat_id){
    const that = this
    var page = that.data.page;
    var more_status = that.data.more_status;
    var new_list = [];
    // let url = '/cardshop_api/queryUsers';
    let url = '/mall/mallsecondseller';
    let params = {
      category_id: cat_id,
      pageno: page,
      city_code: app.globalData.currentCode,
      latitude: app.globalData.latitude,
      longitude: app.globalData.longitude,
      state:0,
      show_start_free: that.data.show_start_free
    }
    app.HttpPostSend(url, params, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        wx.hideLoading();
        if (res.msg !== "success") {
          app.showTipMsg(res.msg);
        } else {
          if (res.seller.length < 10) {
            more_status = false;
          } else {
            more_status = true;
            var page = that.data.page;
            page += 1;
            that.setData({
              page: page
            });
          }
          var list = res.seller;
          for (let i = 0; i < list.length; i++) {
            new_list.push(list[i]);
          }
          console.log(new_list);
          that.setData({
            sj_list: new_list,
            more_status: more_status
          });

        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    console.log(that.data.more_status);
    if (that.data.more_status == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      that.getSeller(that.data.cat_id);

    } else {
      wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  toMyMall:function(e){
    app.globalData.SwitchTabParams.v_id = e.currentTarget.dataset.uid;
    if (e.currentTarget.dataset.food_mall > 0) {
      wx.navigateTo({
        url: '/shopPages/shopxq/shopxq',
      })
    } else {
      wx.navigateTo({
        url: '/shopPages/personalShop/personalShop'
      })
    }
  }
})